import { accountData, getPreIncomeDetail, getIncomeDetail, withdrawCash, getCashDetails } from '../../service/api'


const state = {
  profitPrice : {},
  preincome : {},
  income : {},
  cashLog : {},
}

// getters
const getters = {

    profitPrice : state => state.profitPrice,
    preincome : state => state.preincome,
    income : state => state.income,
    cashLog : state => state.cashLog,
}

// actions
const actions = {

  //五个数
  async getProfitPrice ({ commit, state}, para) {
      let res = await accountData(para.level_code);
      if(res.errcode == 0){
          commit('setProfitPrice', res.data);
      }
  },

  //预收益明细
  async getPreincome ({ commit, state}, para) {
      let res = await getPreIncomeDetail();
      if(res.errcode == 0){
          commit('setPreincome', res.data);
      }
  },

  //实际收益明细
  async getIncome ({ commit, state}, para) {
      let res = await getIncomeDetail(para.level_code);
      if(res.errcode == 0){
          commit('setIncome', res.data);
      }
  },


  //提现
  async cash ({ commit, state}, para) {
      let res = await withdrawCash(parseFloat(para.price * 100).toFixed(0));
      if(res.errcode == 0){
          para.callback(res.data);
      }else{
          para.error(res.errmsg);
      }
  },

  //提现明细
  async getCashLog ({ commit, state}, para) {
      let res = await getCashDetails(para.code);
      if(res.errcode == 0){
          commit('setCashLog', res.data);
      }
  }


}

// mutations
const mutations = {
    setProfitPrice (state, obj) {
        state.profitPrice = obj;
    },
    setPreincome (state, obj) {
        state.preincome = obj;
    },
    setIncome (state, obj) {
        state.income = obj;
    },
    setCashLog (state, obj) {
        state.cashLog = obj;
    },
    
}

export default {
  state,
  getters,
  actions,
  mutations
}
